//自定义一个common.js
import Vue from 'vue'
export default function(Vue){
    //分割成数组
    Vue.prototype.setImgArr =function(imgs) {
        var imgArr = []
        imgs.forEach((item,index) => {
            var obj = {src: item, msrc: item}
            imgArr.push(obj)
        })
        return imgArr
    },
    Vue.prototype.setVoiceArr = function(voices) {
        var arr = []
        for (var item of voices) {
            var obj = {url: item, isPlay: false}
            arr.push(obj)
        }
        return arr
    },
    Vue.prototype.setFileArr = function (files) {
        var fileNameArr = []
        files.FileUrl.forEach(item => {
            var index = item.lastIndexOf(".")
            var suffix = item.substr(index+1)
            fileNameArr.push(suffix)
        })
        return fileNameArr
    }
    //数组根据对象排序
    Vue.prototype.compare = function (val) {
        return function (a, b) {
            var value1 = a[val]
            var value2 = b[val]
            return value1 - value2
        }
    }
    //根据字母排序
    Vue.prototype.compareByABC = function (arr,sortStr) {
        var bySort = function() {
            return function(o, p) {
                var a = o[sortStr],
                    b = p[sortStr]
                if (isNaN(a)) {
                    return a.localeCompare(b)
                } else {
                    if (a === b) {
                        return 0
                    } else {
                        return a > b ? 1 : -1
                    }
                }
            }
        }
        for (var i = 0; i < arr.length; i++) {
            arr.sort(bySort(arr[i][sortStr]))
        }
    }
} 
